<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="所属试卷" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examinationPaperId">
<!--              <a-input v-model="model.examinationPaperId" placeholder="请输入试卷id"  ></a-input>-->
              <a-select v-model="model.examinationPaperId" placeholder="请选择所属试卷"
                        :getPopupContainer="(target) => target.parentNode">
                <a-select-option v-for="item in achExaminationPaperList" :key="item.value">{{ item.label }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="科目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectId">
              <!--              <a-input v-model="model.subjectId" placeholder="请选择所属科目id"  ></a-input>-->
              <a-select v-model="model.subjectId" placeholder="请选择所属科目"
                        :getPopupContainer="(target) => target.parentNode">
                <a-select-option v-for="item in subjectList" :key="item.value">{{ item.label }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目编码(必填)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemCode">
              <a-input v-model="model.exaPapProItemCode" placeholder="请输入考试项目编码(必填)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemName">
              <a-input v-model="model.exaPapProItemName" placeholder="请输入考试项目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目满分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemFullMarks">
              <a-input-number v-model="model.exaPapProItemFullMarks" placeholder="请输入项目满分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemTtype">
<!--              <a-input v-model="model.exaPapProItemTtype" placeholder="请输入项目类型（项目类型（1总分项、2分项、3分项子项））"  ></a-input>-->
              <j-dict-select-tag type="list" v-model="model.exaPapProItemTtype"
                                 dictCode="exa_pap_pro_item_ttype" placeholder="请输入项目类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目子类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemSubTtype">
              <!--              <a-input v-model="model.exaPapProItemSubTtype" placeholder="请输入项目类型（项目类型（1总分项、2分项、3分项子项））"  ></a-input>-->
              <j-dict-select-tag type="list" v-model="model.exaPapProItemSubTtype"
                                 dictCode="exa_pap_pro_item_sub_ttype" placeholder="请输入项目子类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemLevel">
<!--              <a-input-number v-model="model.exaPapProItemLevel" placeholder="请输入项目级别（1一级默认，2二级，3三级）" style="width: 100%" />-->
              <j-dict-select-tag type="list" v-model="model.exaPapProItemLevel"
                                 dictCode="exa_pap_pro_item_level" placeholder="请输入项目级别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上级项目（默认0）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemFatherId">
              <a-input-number v-model="model.exaPapProItemFatherId" placeholder="请输入上级项目（默认0）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemOrder">
              <a-input-number v-model="model.exaPapProItemOrder" placeholder="请输入项目序号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否启用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">
              <j-dict-select-tag type="list" v-model="model.izOpen"
                                 dictCode="iz_open" placeholder="请选择是否启用" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <j-dict-select-tag type="list" v-model="model.delFlag"
                                 dictCode="del_flag" placeholder="请选择是否删除" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createBy">-->
<!--              <a-input v-model="model.createBy" placeholder="请输入创建人"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="修改人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateBy">-->
<!--              <a-input v-model="model.updateBy" placeholder="请输入修改人"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import { getSubjectList, getAllAchExaminationPaperList} from '@api/achievementCommonAPI'

  export default {
    name: 'AchExamPaperProjectItemForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/achexampaperprojectitem/achExamPaperProjectItem/add",
          edit: "/achexampaperprojectitem/achExamPaperProjectItem/edit",
          queryById: "/achexampaperprojectitem/achExamPaperProjectItem/queryById"
        },
        achExaminationPaperList: [],
        subjectList: [],
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.getAchExaminationPaperData();
      this.getSubjectData();
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      async getSubjectData() {
        let res = await getSubjectList()
        this.subjectList = []
        res.result.records.forEach(item => {
          this.subjectList.push({
            label: item.subjectName,
            value: item.id
          })
        })
      },
      async getAchExaminationPaperData() {
        let res = await getAllAchExaminationPaperList()
        this.achExaminationPaperList = []
        res.result.records.forEach(item => {
          this.achExaminationPaperList.push({
            label: item.examinationPaperName,
            value: item.id
          })
        })
      },


    }
  }
</script>